package controller;

import com.github.pagehelper.PageInfo;
import domain.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import service.IOrderService;

import java.util.List;

/**
 * @author ：Yan Guang
 * @date ：Created in 2020/9/15 17:02
 * @description：
 */
@Controller
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

    /*@RequestMapping("/findAll.do")
    public ModelAndView finAll() throws Exception {
        ModelAndView mv = new ModelAndView();
        List<Orders> os = iOrderService.findAll();
        mv.addObject("ordersList",os);
        mv.setViewName("orders-list");
        return mv;
    }*/
    @RequestMapping("/findAll.do")
    public ModelAndView finAll(@RequestParam(name = "page", required = true, defaultValue = "1") Integer page, @RequestParam(name = "size", required = true, defaultValue = "4") Integer size) throws Exception {
        ModelAndView mv = new ModelAndView();
        List<Orders> list = iOrderService.findAll(page, size);
        PageInfo pageInfo = new PageInfo(list);
        mv.addObject("pageInfo", pageInfo);
        mv.setViewName("orders-page-list");
        return mv;
    }
    @RequestMapping("/findById.do")
    public ModelAndView findById(@RequestParam(name = "id", required = true) int orderId) throws Exception {
        ModelAndView mv = new ModelAndView();
        Orders orders = iOrderService.findById(orderId);
        PageInfo pageInfo = new PageInfo();
        mv.addObject("orders",orders);
        mv.setViewName("orders-show");
        return mv;
    }
}
